class Map < ActiveRecord::Base
  validates_x :presence => true
  validates_y :presence => true
  validates_z :presence => true
  validates_z :uniqueness => true, :scope => [:x, :y]
  validates_title :presence => true
  
  has_many :heros
  has_many :exits, :dependent => :destroy
  
  def to_s
    title
  end
  
  def coordinates
    x.to_s ":" << y.to_s << ":" << z.to_s
  end
  
  def has_exit(map)
    self.exits.each do |exit|
      return true if exit.destination_id == map.id
    end
    false
  end
end
